#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

class Solution {
public:
    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
        if (start > destination) swap(start, destination);
        return min(accumulate(distance.begin() + start, distance.begin() + destination, 0),
            accumulate(distance.begin(), distance.begin() + start, 0) + accumulate(distance.begin() + destination, distance.end(), 0));
    }

    int missingNumber(vector<int>& nums) {
        int ans = 0, n = nums.size();
        for (int i = 0; i < nums.size(); ++i)
        {
            ans ^= i, ans ^= nums[i];
        }
        return ans ^ n;
    }

    int missingNumber(vector<int>& nums) {
        int ans = 0, n = nums.size();
        int sum = n * (n + 1) / 2, misssum = 0;
        for (int i = 0; i < nums.size(); ++i)
        {
            misssum += nums[i];
        }
        return sum - misssum;
    }

    int getSum(int a, int b) {
        while (b != 0)
        {
            int x = a ^ b;
            int carry = (a & b) << 1;
            a = x;
            b = carry;
        }
        return a;
    }

    int singleNumber(vector<int>& nums) {
        int ret = 0;
        for (int i = 0; i < 32; ++i)
        {
            int sum = 0;
            for (auto num : nums)
                sum += (num >> i) & 1;
            sum %= 3;
            if (sum == 1)
                ret |= (1 << i);
        }
        return ret;
    }
};